package com.da.javatest.correct;

import java.io.Serializable;

public class Result<T> implements Serializable {

    private static final long serialVersionUID = -5449567850972102911L;

    /**
     * 是否成功
     */
    private boolean success;

    /**
     * 主体数据
     */
    private T data;

    /**
     * 错误信息
     */
    private String msg;

    /**
     * 错误编码
     */
    private String errorCode;

    public Result() {
    }

    public Result(T data) {
        this(true, data, null);
    }

    public Result(String msg) {
        this(false, null, msg);
    }

    public Result(boolean success, T data, String msg) {
        this.success = success;
        this.data = data;
        this.msg = msg;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "Result{success=" + success + ", data=" + data + ", msg='" + msg + '\'' + '}';
    }

    public static <T> Result<T> succ(T data) {
        return new Result<>(data);
    }

    public static <T> Result<T> fail(String msg) {
        return new Result<>(msg);
    }

}
